package com.swotxu.hhprovider.health;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

/**
 * 模拟检查数据库连接是否成功的健康指示器
 *
 * @Date: 2020/7/4 16:18
 * @Author: swotXu
 */
@Component
public class MyHealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
        Health.Builder builder = new Health.Builder();
        // 数据库连接：成功返回 UP，失败返回 DOWN
        return HealthController.canVisitDb?
                builder.up().build() : builder.down().build();
    }
}
